class StoriesController < ApplicationController
  
  before_filter :login_required
  
  # /stories
  def index
    @stories = Story.all_active
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @stories }
    end
  end
  
  # /stories/new
  def new
    @story = Story.new
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @story }
    end
  end
  
  def create
    @story = Story.new(params[:story])

    # set the default start state
    @story.story_state = StoryState.find(:first, :order => "id");

    # set the created by user
    @story.created_by_user_id = current_user.id

    respond_to do |format|
      if @story.save
        flash[:notice] = 'Story was successfully created.'
        format.html { redirect_to(@story) }
        format.xml  { render :xml => @story, :status => :created, :location => @story }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @story.errors, :status => :unprocessable_entity }
      end
    end
  end
  
end